package com.itheima.service.db.impl;/*
 * @author  xs
 * @date 2022/1/15 10:38
 * @Version  1.0
 * */

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.vo.PageBeanVo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.service.db.BackGroupService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class BackGroupServiceImpl implements BackGroupService {
    @Autowired
    private UserInfoMapper userInfoMapper;
//    分页查询用户
    @Override
    public PageBeanVo findAllUser(Integer pagNum, Integer pageSize) {
//        分页对象
        IPage<UserInfo> userInfoIPage =new Page<>(pagNum,pageSize);
//        按照创建时间排序
        QueryWrapper<UserInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("created");
        userInfoIPage = userInfoMapper.selectPage(userInfoIPage, queryWrapper);

//        查询所有用户
        List<UserInfo> userList = userInfoMapper.selectList(null);
        return new PageBeanVo(pagNum,pageSize,userInfoIPage.getTotal(),userList);
    }
}
